<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <meta name="Keywords" content="FreeMarker, template, templates, HTML, HTML template, page template, text, macro, macros, preprocessor, MVC, view, servlet, Java, free, open source, JSP, taglib, Velocity, WebMacro">
    <meta name="Description" content="Java template engine; a generic tool to generate text output (HTML, RTF, source code, etc.). Practical for servlet-based Web applications following the MVC pattern. Free.">
    <meta name="verify-v1" content="OU7KNU7q+wGizVoaX/MNUo/tZ5o5RC06VfCjQIRRJu4=">
    <link rel="STYLESHEET" type="text/css" href="site.css">
    <title>FreeMarker: Java Template Engine Library - FreeMarker vs. Velocity</title>
  </head>
  <body>
    <table border="0" cellspacing="0" cellpadding="0" width="100%">
      <tr>
        <td align="left" valign="top" width="20%">
  <table bgcolor="#E0E0E0" cellspacing="0" cellpadding="0" border="0" width="100%">
    <tr valign="top">
      <td height="1" width="1" bgcolor="black"><img src="images/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"></td>
      <td height="1" bgcolor="black"><img src="images/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"></td>
      <td height="1" width="1" bgcolor="black"><img src="images/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"></td>
    </tr>
    <tr>
      <td width="1" bgcolor="black"><img src="images/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td>
      <td>
        <table bgcolor="#E0E0E0" cellspacing="0" cellpadding="0" border="0" width="100%" style="margin: 0px">
          <tr><td>

  <table bgcolor="#E0E0E0" border="0" cellspacing="10" cellpadding="0" width="100%">
    <tr><td colspan="2" align="center">
        <a href="http://freemarker.org"><img border="0" src="images/logo_e0e0e0.png" alt="FreeMarker logo"></a><br>&nbsp;
    </td></tr>

  
    <tr><td>
  <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr><td width="100%">
      <b>About</b>
    </td></tr>
  </table>
  <table border="0" cellpadding="0" cellspacing="0" width="100%">

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="index.html">Overview</a>
    </td>
  </tr>

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="features.html">Features</a>
    </td>
  </tr>

      </table>
</td></tr>

    <tr><td>
  <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr><td width="100%">
      <b>Download</b>
    </td></tr>
  </table>
  <table border="0" cellpadding="0" cellspacing="0" width="100%">

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="freemarkerdownload.html">FreeMarker</a>
    </td>
  </tr>

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="editors.html">Editor/IDE plugins</a>
    </td>
  </tr>

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="fmpp.html">File generator tool (FMPP)</a>
    </td>
  </tr>

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="usCavalry.html">Migrating from Velocity</a>
    </td>
  </tr>

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="libraries.html">FTL Libraries</a>
    </td>
  </tr>

      </table>
</td></tr>

    <tr><td>
  <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr><td width="100%">
      <b>Documentation</b>
    </td></tr>
  </table>
  <table border="0" cellpadding="0" cellspacing="0" width="100%">

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="docs/index.html">Table of Contents</a>
    </td>
  </tr>

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="docs/api/index.html">Short-cut to: Java API</a>
    </td>
  </tr>

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="docs/app_faq.html">Short-cut to: FAQ</a>
    </td>
  </tr>

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="docs/alphaidx.html">Short-cut to: Index</a>
    </td>
  </tr>

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="docs/app_versions.html">Short-cut to: Versions</a>
    </td>
  </tr>

      </table>
</td></tr>

    <tr><td>
  <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr><td width="100%">
      <b>Community, help</b>
    </td></tr>
  </table>
  <table border="0" cellpadding="0" cellspacing="0" width="100%">

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="http://sourceforge.net/tracker/?func=add&amp;group_id=794&amp;atid=100794">REPORT BUGS HERE!</a>
    </td>
  </tr>

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="http://sourceforge.net/mail/?group_id=794">Mailing list subscription</a>
    </td>
  </tr>

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="gmane.html">Browse/search the mailing list archives</a>
    </td>
  </tr>

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="gmane.html">News (nntp) interface</a>
    </td>
  </tr>

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="https://sourceforge.net/forum/?group_id=794">Web forums</a>
    </td>
  </tr>

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="http://freemarker.org/builds/">Development builds (automatic)</a>
    </td>
  </tr>

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="http://freemarker.org/wiki">Wiki</a>
    </td>
  </tr>

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="http://freemarker.blogspot.com/">Blog</a>
    </td>
  </tr>

      </table>
</td></tr>

    <tr><td>
  <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr><td width="100%">
      <b>Miscellaneous</b>
    </td></tr>
  </table>
  <table border="0" cellpadding="0" cellspacing="0" width="100%">

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="poweredBy.html">Powered by FreeMarker</a>
    </td>
  </tr>

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="http://sourceforge.net/projects/freemarker">SourceForge project page</a>
    </td>
  </tr>

        <tr>
    <td align="left" valign="top"><img src="images/bullet_e0e0e0.png" width=7 height=10 alt="-">&nbsp;</td>
    <td width="93%" align="left">
      <a class="nav" href="whoWeAre.html">Who we are</a>
    </td>
  </tr>

      </table>
</td></tr>

  
  </table>

          </td></tr>
        </table>
      </td>
      <td width="1" bgcolor="black"><img src="images/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td>
    </tr>
    <tr valign="top">
      <td height="1" width="1" bgcolor="black"><img src="images/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"></td>
      <td height="1" bgcolor="black"><img src="images/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"></td>
      <td height="1" width="1" bgcolor="black"><img src="images/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"></td>
    </tr>
  </table>            
        </td>
        <td align="left" valign="top" width="5%">
          &nbsp;
        </td>
        <td align="left" valign="top" width="72%">
          <table border="0" cellspacing="0" cellpadding="0" width="100%">
            <tr><td align="right"><span class="pageTitle">FreeMarker vs. Velocity</span></td></tr>
            <tr bgcolor="#000000"><td><img src="images/none.gif" width=1 height=1 hspace="0" vspace="0" border="0" alt=""></td></tr>
          </table>

  
    <p>
      <a href="http://jakarta.apache.org/velocity/index.html">Velocity</a> is a
      simpler, more lightweight tool. Thus, it does not address
      many tasks that FreeMarker does, and its template language is less
      powerful in general, but it is simpler.
    </p>
    <p>However, we think
      that for most applications, working with FreeMarker is simpler than
      working with Velocity, since with Velocity you have to find custom tools and find various other workarounds to solve typical template authoring tasks again and again, and you end up losing much more time in the long run than you have won on the quick starting. Also, the result of solving something with tools and workarounds is most probably not as terse or efficient as the solution in the engine core. Furthermore, according to Velocity list archives, the workaround often means extensive direct usage of Java object methods in the Velocity template (this violates the idea of simple, non-programmer HTML-designer friendly templates) or the movement of presentation tasks into the controller code (this violates the MVC idea).
      And, after all, if you use FreeMarker only for what Velocity can do out-of-the-box, it is as simple as Velocity.
    </p>
    <p>
      An advantage of Velocity over FreeMarker is that Velocity has wider third party support and a much larger user community.
      However, you might need less support for FreeMarker because instead of creating and discussing workarounds you might often be able
      to simply use FreeMarker standard features. And in case you have difficulties there are of course active web forums and mailing lists.
      Moreover, since with FreeMarker you can use Model-2 frameworks as Struts and any JSP tag libraries out-of-the-box, perhaps third-party support is not a that big problem if you are in the servlet segment. Also, more and more servlet frameworks adapt FreeMarker as their view layer, next to JSP and Velocity.
    </p>
       <p>   
      There are other parameters that should be considered when you compare
      tools, like code quality and documentation quality. But of course, we as
      the authors of the product should not say anything about this.
      It is up to the users to judge.
    </p>
  
  
    <h2>Feature comparison sheet</h2>

      <p>
      Here's a quick, non-comprehensive listing of things you can do with
        FreeMarker out of the box, and which you can not do with Velocity (or, 
        you can but only with nontrivial workarounds).
        This list is originally based on a comparison with Velocity 1.2. 
        Contact us for change suggestions.
      </p>
      
      <p>Number and date support</p>
      <ul>
        <li>You can perform arithmetic calculations and comparisons on arbitrary number types, including the arbitrary-precision types, not just integers.</li>
        <li>You can compare and display (format) date/time values.</li>
      </ul>

      <p>Internationalization:</p>
      <ul>
        <li>You can format numbers locale-sensitively, based on a variety of built-in and custom number-formatting patterns.</li>
        <li>You can format dates locale- and timezone-sensitively, based on variety of built-in and custom date-formatting patterns.</li>
        <li>Identifiers (variable names) can contain non-English letters like accented letters, Arabic letters, Chinese letters, etc.</li>
      </ul>
      
      <p>Loop handling:</p>
      <ul>
        <li>You can break out of loops.</li>
        <li>You can access control variables of outer loops from bodies of inner loops.</li>
        <li>You can test whether you are in the last iteration of the loop.</li>
      </ul>

      <p>Array handling on the template language level:</p>
      <ul>
        <li>You can access array elements, both primitive and non-primitive by index using the familiar <tt>[i]</tt> syntax.</li>
        <li>You can query the length of an array.</li>
      </ul>

      <p>Macros:</p>
      <ul>
        <li>Macro invocations can pass parameters either by position or by name.</li>
        <li>Macro parameters can have default values which are effective when the parameter is omitted on invocation.</li>
        <li>Macro invocations can have a nested body (<code>&lt;@myMacro><i>body</i>&lt;/@myMacro></code>) that can be called by the macro for processing.</li>
        <li>Macros are plain variables, so you can select the macro to execute based on an expression, or pass a
            macro to another macro as parameter.</li>
        <li>Invoke a macro that is defined later in the template.</li>
        <li>Local variables in macros, and recursive invocation of macros. In Velocity it is now possible with the currently (Feb. 2005) not officially documented <tt>#local</tt> function.</li>
      </ul>

      <p>Name-spaces:</p>
      <ul>
        <li>You can use multiple name-spaces for variables. This is invaluable when you build "macro libraries", because you can prevent name collisions with application specific variables or with variables of other macro libraries.</li>
      </ul>

      <p>Java-independent string, list, and map manipulations with built-in functions/operators:</p>
      <ul>
        <li>You can turn a string upper-, lower-, or title-case, turn upper-/lowercase only the first letter,
        convert (escape) the string to HTML, XML, or RTF, extract substrings, split strings, query string length,
        find/replace substring, ...etc.</li>
        <li>Access elements of lists by index, extract sublists, concatenate lists, query 
        size of a lists, sort lists.</li>
        <li>Access map elements by variable key, check if the map is empty, obtain the key or value list.</li>
      </ul>

      <p>Expose typos and other mistakes in template:</p>
      <ul>
        <li>When you try to access an undefined variable, FreeMarker will not accept that silently.
        You can configure FreeMarker to stop template rendering with an error message, or skip the wrong part.
        In either case, FreeMarker will log the problem, so it does not remain hidden.</li>
        <li>FreeMarker will throw an exception if you mistype a directive name,
        and will not print the statement silently to the output (unless you use the now deprecated non-strict syntax).</li>
      </ul>

      <p>Advanced rendering control:</p>
      <ul>
        <li>You can enclose a block of template in a set of tags that will
        cause it to apply HTML escaping or XML escaping (or any other 
        transformation you can express as a FreeMarker expression for that
        matter) on all interpolations (<code>${foo}</code>) in the block.</li>
        <li>FreeMarker has transforms, which are blocks of template that when
        rendered, go through a transforming filter. Built-in transforms
        include whitespace compressor, HTML and XML escaper.
        Best of all, you can implement your own transformers as well
        (i.e. if you generate Java source code, you can write a Java code
        pretty-printer transform and insert it into the template). Naturally,
        transforms can be nested.</li>
        <li>You can explicitly flush the output writer with a built-in flush-directive.</li>
        <li>You can stop the rendering with a built-in stop-directive.</li>
      </ul>

      <p>Literals:</p>
      <ul>
        <li>Beside the usual string, number, and boolean literals you can define
        list and map literals as well inside templates.</li>
        <li>There is a support for all Java string literal escapes: 
        <tt>\b</tt>, <tt>\t</tt>, <tt>\n</tt>, <tt>\f</tt>, <tt>\r</tt>, 
        <tt>\"</tt>, <tt>\'</tt>, <tt>\\</tt>, also we support <tt>\xXXXX</tt> to
        specify characters with their UNICODE code.</li>
      </ul>

      <p>Advanced white-space removal:</p>
      <ul>
        <li>FreeMarker consistently removes white-space (spaces, tabs and line-break) from
        lines that contain non-outputting FreeMarker tags only, thus eliminates most annoying, obviously superfluous white-space.</li>
        <li>There are directives to explicitly trim lines from needless white-space,
        just for the extreme cases, when white-space is a real problem.</li>
      </ul>

      <p>Integration with other technologies:</p>
      <ul>
        <li>You can use JSP custom tag libraries in templates.</li>
        <li>You can work directly on Python objects.</li>
      </ul>
      
      <p>Powerful XML transformation capabilities:</p>
      <ul>
         <li>As of version 2.3, FreeMarker has powerful new XML transformation capabilities that make it a viable replacement for XSLT. Though there have been some attempts to make Velocity more
         capable in this domain (i.e. DVSL) Velocity is not really competitive in this regard. In our view, it never will be unless certain improvements to the core engine are made, such as support for macro libraries mapped to namespaces, and local variables in macros.</li>
         <li>See <a href="fmVsXSLT.html">here</a> for a more detailed comparison of FreeMarker and XSLT.</li>
      </ul>
      <p>Advanced template metaprogramming:</p>
      <ul>
        <li>You can capture the output of an arbitrary part of the template into a context variable.</li>
        <li>You can interpret arbitrary context variable as if it were a template definition.</li>
        <li>You can imagine what can you do when you combine the two...</li>
      </ul>
    
  
        </td>
        <td align="left" valign="top" width="3%" rowspan=3>
          &nbsp;
        </td>
      </tr>
    </table>

    <p>&nbsp;
    
    <table border=0 cellspacing=0 cellpadding=0 width="100%">
      <tr><td height=1 bgcolor="#C0C0C0"><img src="images/none.gif" width=1 height=1 alt=""></td></tr>
    </table>
    <table border=0 cellspacing=0 cellpadding=0 width="100%">
      <tr>
      <td align=left valign=top class="footnote"><font size="1">&nbsp;<br></font>
        <b>Found broken link or other problem with this site?</b><br>
        Report to: <a href="mailto:ddekanyREMOVEME@freemail.hu">ddekanyREMOVEME@freemail.hu</a><br>
        (remove the "REMOVEME" from the address)<br>
      </td>
      <td align=right valign=top class="footnote"><font size="1">&nbsp;<br></font>
        Page last generated: 2009-12-08 08:39:00 GMT<br>
        All content on this page is copyrighted by the FreeMarker project.<br>
        &nbsp;
      </td>
    </table>

    <table border=0 cellspacing=0 cellpadding=0 width="100%">
      <tr>
        <td width="100%">&nbsp;</td>
        <td valign="middle" align="right">
            <a href="http://sourceforge.net"><img src="images/sflogo.png" border="0" alt="SourceForge Logo"></a>
        </td>
        <td>
          &nbsp;&nbsp;
        </td>
        <td valign="middle" align="right">
          <a href="http://freemarker.org"><img src="images/poweredby_ffffff.png" alt="Powered by FreeMarker" border="0"></a>
        </td>
    </table>
  </body>
</html>



